package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/category")
@RestController
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping
    public Result<String> add(@RequestBody CategoryDTO categoryDTO){
        categoryService.add(categoryDTO);
        return Result.success("添加分类成功");
    }
    @GetMapping("page")
    public Result<PageResult>page(CategoryPageQueryDTO categoryPageQueryDTO){
       PageResult pageResult =categoryService.page(categoryPageQueryDTO);
       return Result.success(pageResult);
    }
    @PostMapping("/status/{status}")
    public Result<String>updateStartus(@PathVariable("status") int status,Long id){
        categoryService.updateStartus(status,id);
        return Result.success("状态修改成功");
    }
    @DeleteMapping
    public Result<String>deleteById(Long id){
        categoryService.deleteById(id);
        return Result.success("删除成功");
    }
    @GetMapping("/list")
    public Result<List<Category>>selectByIds(Integer type){
        List<Category> categories = categoryService.selectByType(type);
        return Result.success(categories);

    }
    @PutMapping
    @ApiOperation("修改分类")
    public Result<String> update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }

}
